﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACC.Extensions.PCClient.Entities
{
    /// <summary>
    /// 条码列表子项
    /// </summary>
    public class BarCodeItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 条码名称
        /// </summary>
        private string idName;

        public string IDName
        {
            get
            { return idName; }
            set
            {
                idName = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IDName"));
                }
            }
        }

        /// <summary>
        /// ItemPartNo
        /// </summary>
        public string ItemPartNo { get; set; }

        /// <summary>
        /// 是否为主条码
        /// </summary>
        public bool LeadNo { get; set; }

        /// <summary>
        /// 条码个数
        /// </summary>
        public int Qty { get; set; }

        /// <summary>
        /// 条码顺序
        /// </summary>
        public int Order { get; set; }

        /// <summary>
        /// 前端显示的名称
        /// 相同IDName绑定多个数量时，显示名称加上下标
        /// </summary>
        /// 
        private string showName;
        public string ShowName
        {
            get
            {
                return showName;
            }
            set
            {
                showName = Qty > 1 ? string.Format("{0}_{1}", IDName, Order) : IDName;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("ShowName"));
                }
            }
        }

        /// <summary>
        /// 条码格式
        /// </summary>
        public string IDPattern { get; set; }

        /// <summary>
        /// 条码值
        /// </summary>
        private string idValue;
        public string IDValue
        {
            get { return idValue; }
            set
            {
                idValue = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IDValue"));
                }
            }
        }

        /// <summary>
        /// 是否为在当前OP绑定
        /// </summary>
        private bool isCurrentOP;
        public bool IsCurrentOP
        {
            get { return isCurrentOP; }
            set
            {
                isCurrentOP = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsCurrentOP"));
                }
            }
        }

        /// <summary>
        /// 条码状态
        /// </summary>
        private BarcodeStatus status;
        public BarcodeStatus Status
        {
            get { return status; }
            set
            {
                status = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Status"));
                }
            }
        }
    }

    public enum BarcodeStatus
    {
        Init = 0,  //扫码，未验证
        OK = 1,   //验证通过
        NOK = 2   //验证不通过
    }
}
